using System;
namespace MicroMsg.Common.Audio.Amr.Resampler
{
	public class GloabFunc
	{
		public delegate int resampler_basic_func(GloabFunc.ResamplerState resamplerState, uint uintP1, float[] fP1, int fP1Offset, ref uint uintP2, float[] fP2, int fP2Offset, ref uint uintP3);
		public class ResamplerState
		{
			public uint in_rate;
			public uint out_rate;
			public uint num_rate;
			public uint den_rate;
			public int quality;
			public uint nb_channels;
			public uint filt_len;
			public uint mem_alloc_size;
			public int int_advance;
			public int frac_advance;
			public float cutoff;
			public uint oversample;
			public int initialised;
			public int started;
			public int[] last_sample;
			public int last_sampleOffset;
			public uint[] samp_frac_num;
			public int samp_frac_numOffset;
			public uint[] magic_samples;
			public int magic_samplesOffset;
			public float[] float_0;
			public int memOffset;
			public float[] sinc_table;
			public int sinc_tableOffset;
			public uint sinc_table_length;
			public GloabFunc.resampler_basic_func resampler_ptr;
			public int in_stride;
			public int out_stride;
			public ResamplerState()
			{
				this.in_rate = 0u;
				this.out_rate = 0u;
				this.num_rate = 0u;
				this.den_rate = 0u;
				this.quality = 0;
				this.nb_channels = 0u;
				this.filt_len = 0u;
				this.mem_alloc_size = 0u;
				this.int_advance = 0;
				this.frac_advance = 0;
				this.cutoff = 0f;
				this.oversample = 0u;
				this.initialised = 0;
				this.started = 0;
				this.last_sample = null;
				this.last_sampleOffset = 0;
				this.samp_frac_num = null;
				this.samp_frac_numOffset = 0;
				this.magic_samples = null;
				this.magic_samplesOffset = 0;
				this.float_0 = null;
				this.memOffset = 0;
				this.sinc_table = null;
				this.sinc_tableOffset = 0;
				this.sinc_table_length = 0u;
				this.in_stride = 0;
				this.out_stride = 0;
			}
		}
		public const int FIXED_STACK_ALLOC = 1024;
		private static byte[] xve_alloc(int size)
		{
			return new byte[size];
		}
		private static float[] xve_realloc(float[] float_0, int ptrOffset, int size)
		{
			float[] array = new float[size];
			int num = Math.Min(size, float_0.Length - ptrOffset);
			Array.Copy(float_0, ptrOffset, array, 0, num);
			return array;
		}
		private static void xve_free(byte[] byte_0)
		{
		}
		private static short QCONST16(int int_0, int bits)
		{
			return (short)int_0;
		}
		private static int QCONST32(int int_0, int bits)
		{
			return int_0;
		}
		private static short NEG16(int int_0)
		{
			return (short)(int_0 * -1);
		}
		private static int NEG32(int int_0)
		{
			return int_0 * -1;
		}
		private static short EXTRACT16(int int_0)
		{
			return (short)int_0;
		}
		private static int EXTEND32(int int_0)
		{
			return int_0;
		}
		private static short SHR16(short short_0, int shift)
		{
			return short_0;
		}
		private static short SHL16(short short_0, int shift)
		{
			return short_0;
		}
		private static int SHR32(int int_0, int shift)
		{
			return int_0;
		}
		private static int SHL32(int int_0, int shift)
		{
			return int_0;
		}
		private static short PSHR16(short short_0, int shift)
		{
			return short_0;
		}
		private static int PSHR32(int int_0, int shift)
		{
			return int_0;
		}
		private static float PSHR32(float float_0, int shift)
		{
			return float_0;
		}
		private static int VSHR32(int int_0, int shift)
		{
			return int_0;
		}
		private static short SATURATE16(short short_0, int int_0)
		{
			return short_0;
		}
		private static int SATURATE32(short short_0, int int_0)
		{
			return (int)short_0;
		}
		private static short PSHR(short short_0, int shift)
		{
			return short_0;
		}
		private static short SHR(short short_0, int shift)
		{
			return short_0;
		}
		private static short SHL(short short_0, int shift)
		{
			return short_0;
		}
		private static short SATURATE(short short_0, int int_0)
		{
			return short_0;
		}
		private static int ADD16(int int_0, int int_1)
		{
			return int_0 + int_1;
		}
		private static int SUB16(int int_0, int int_1)
		{
			return int_0 - int_1;
		}
		private static int ADD32(int int_0, int int_1)
		{
			return int_0 + int_1;
		}
		private static int SUB32(int int_0, int int_1)
		{
			return int_0 - int_1;
		}
		private static int MULT16_16_16(int int_0, int int_1)
		{
			return int_0 * int_1;
		}
		private static float MULT16_16(float float_0, float float_1)
		{
			return float_0 * float_1;
		}
		private static double MULT16_16(double double_0, double double_1)
		{
			return double_0 * double_1;
		}
		private static float MAC16_16(float float_0, float float_1, float float_2)
		{
			return float_0 + float_1 * float_2;
		}
		private static int MULT16_32_Q11(int int_0, int int_1)
		{
			return int_0 * int_1;
		}
		private static int MULT16_32_Q13(int int_0, int int_1)
		{
			return int_0 * int_1;
		}
		private static int MULT16_32_Q14(int int_0, int int_1)
		{
			return int_0 * int_1;
		}
		private static int MULT16_32_Q15(int int_0, int int_1)
		{
			return int_0 * int_1;
		}
		private static float MULT16_32_Q15(float float_0, float float_1)
		{
			return float_0 * float_1;
		}
		private static int MULT16_32_P15(int int_0, int int_1)
		{
			return int_0 * int_1;
		}
		private static int MAC16_32_Q11(int int_0, int int_1, int int_2)
		{
			return int_0 + int_1 * int_2;
		}
		private static int MAC16_32_Q15(int int_0, int int_1, int int_2)
		{
			return int_0 + int_1 * int_2;
		}
		private static int MAC16_16_Q11(int int_0, int int_1, int int_2)
		{
			return int_0 + int_1 * int_2;
		}
		private static int MAC16_16_Q13(int int_0, int int_1, int int_2)
		{
			return int_0 + int_1 * int_2;
		}
		private static int MAC16_16_P13(int int_0, int int_1, int int_2)
		{
			return int_0 + int_1 * int_2;
		}
		private static int MULT16_16_Q11_32(int int_0, int int_1)
		{
			return int_0 * int_1;
		}
		private static int MULT16_16_Q13(int int_0, int int_1)
		{
			return int_0 * int_1;
		}
		private static int MULT16_16_Q14(int int_0, int int_1)
		{
			return int_0 * int_1;
		}
		private static int MULT16_16_Q15(int int_0, int int_1)
		{
			return int_0 * int_1;
		}
		private static int MULT16_16_P15(int int_0, int int_1)
		{
			return int_0 * int_1;
		}
		private static int MULT16_16_P13(int int_0, int int_1)
		{
			return int_0 * int_1;
		}
		private static int MULT16_16_P14(int int_0, int int_1)
		{
			return int_0 * int_1;
		}
		private static float DIV32_16(float float_0, float float_1)
		{
			return float_0 / float_1;
		}
		private static float PDIV32_16(float float_0, float float_1)
		{
			return float_0 / float_1;
		}
		private static float DIV32(float float_0, float float_1)
		{
			return float_0 / float_1;
		}
		private static float PDIV32(float float_0, float float_1)
		{
			return float_0 / float_1;
		}
		public static short WORD2INT(float float_0)
		{
			return (short)((float_0 < -32767.5f) ? -32768f : ((float_0 > 32766.5f) ? 32767f : ((float)Math.Floor(0.5 + (double)float_0))));
		}
		public static float IMAX(float float_0, float float_1)
		{
			if (float_0 <= float_1)
			{
				return float_1;
			}
			return float_0;
		}
		public static float IMIN(float float_0, float float_1)
		{
			if (float_0 >= float_1)
			{
				return float_1;
			}
			return float_0;
		}
		public static double compute_func(float float_0, FuncDef func)
		{
			double[] array = new double[4];
			float num = float_0 * (float)func.oversample;
			int num2 = (int)Math.Floor((double)num);
			float num3 = num - (float)num2;
			array[3] = -0.1666666667 * (double)num3 + 0.1666666667 * (double)(num3 * num3 * num3);
			array[2] = (double)num3 + 0.5 * (double)(num3 * num3) - 0.5 * (double)(num3 * num3 * num3);
			array[0] = -0.3333333333 * (double)num3 + 0.5 * (double)(num3 * num3) - 0.1666666667 * (double)(num3 * num3 * num3);
			array[1] = 1.0 - array[3] - array[2] - array[0];
			return array[0] * func.table[func.tableOffset + num2] + array[1] * func.table[func.tableOffset + num2 + 1] + array[2] * func.table[func.tableOffset + num2 + 2] + array[3] * func.table[func.tableOffset + num2 + 3];
		}
		private static float sinc(float cutoff, float float_0, int N, FuncDef window_func)
		{
			float num = float_0 * cutoff;
			if ((double)Math.Abs(float_0) < 1E-06)
			{
				return cutoff;
			}
			if ((double)Math.Abs(float_0) > 0.5 * (double)N)
			{
				return 0f;
			}
			return cutoff * (float)Math.Sin((double)(3.14159274f * num)) / (3.14159274f * num) * (float)GloabFunc.compute_func((float)Math.Abs(2.0 * (double)float_0 / (double)N), window_func);
		}
		private static void cubic_coef(float frac, float[] interp, int interpOffset)
		{
			interp[interpOffset] = -0.16667f * frac + 0.16667f * frac * frac * frac;
			interp[interpOffset + 1] = frac + 0.5f * frac * frac - 0.5f * frac * frac * frac;
			interp[interpOffset + 3] = -0.33333f * frac + 0.5f * frac * frac - 0.16667f * frac * frac * frac;
			interp[interpOffset + 2] = 1f - interp[interpOffset] - interp[interpOffset + 1] - interp[interpOffset + 3];
		}
		private static int resampler_basic_direct_single(GloabFunc.ResamplerState resamplerState_0, uint channel_index, float[] _in, int _inOffset, ref uint in_len, float[] _out, int _outOffset, ref uint out_len)
		{
			int filt_len = (int)resamplerState_0.filt_len;
			int num = 0;
			int num2;
			uint num3;
			float[] float_;
			checked
			{
				num2 = resamplerState_0.last_sample[(int)((IntPtr)unchecked((long)resamplerState_0.last_sampleOffset + (long)((ulong)channel_index)))];
				num3 = resamplerState_0.samp_frac_num[(int)((IntPtr)unchecked((long)resamplerState_0.samp_frac_numOffset + (long)((ulong)channel_index)))];
				float_ = resamplerState_0.float_0;
			}
			int num4 = resamplerState_0.memOffset + (int)(channel_index * resamplerState_0.mem_alloc_size);
			while (num2 < (int)in_len && num < (int)out_len)
			{
				float num5 = 0f;
				int i = 0;
				while (num2 - filt_len + 1 + i < 0)
				{
					num5 += GloabFunc.MULT16_16(float_[num4 + num2 + i], resamplerState_0.sinc_table[resamplerState_0.sinc_tableOffset + (int)(num3 * resamplerState_0.filt_len) + i]);
					i++;
				}
				if (_in != null)
				{
					int num6 = _inOffset + resamplerState_0.in_stride * (num2 - filt_len + 1 + i);
					while (i < filt_len)
					{
						num5 += GloabFunc.MULT16_16(_in[num6], resamplerState_0.sinc_table[(int)checked((IntPtr)unchecked((long)resamplerState_0.sinc_tableOffset + (long)((ulong)(num3 * resamplerState_0.filt_len)) + (long)i))]);
						num6 += resamplerState_0.in_stride;
						i++;
					}
				}
				_out[_outOffset] = GloabFunc.PSHR32(num5, 15);
				_outOffset += resamplerState_0.out_stride;
				num++;
				num2 += resamplerState_0.int_advance;
				num3 += (uint)resamplerState_0.frac_advance;
				if (num3 >= resamplerState_0.den_rate)
				{
					num3 -= resamplerState_0.den_rate;
					num2++;
				}
			}
			checked
			{
				resamplerState_0.last_sample[(int)((IntPtr)unchecked((long)resamplerState_0.last_sampleOffset + (long)((ulong)channel_index)))] = num2;
				resamplerState_0.samp_frac_num[(int)((IntPtr)unchecked((long)resamplerState_0.samp_frac_numOffset + (long)((ulong)channel_index)))] = num3;
				return num;
			}
		}
		private static int resampler_basic_direct_double(GloabFunc.ResamplerState resamplerState_0, uint channel_index, float[] _in, int _inOffset, ref uint in_len, float[] _out, int _outOffset, ref uint out_len)
		{
			int filt_len = (int)resamplerState_0.filt_len;
			int num = 0;
			int num2;
			uint num3;
			float[] float_;
			checked
			{
				num2 = resamplerState_0.last_sample[(int)((IntPtr)unchecked((long)resamplerState_0.last_sampleOffset + (long)((ulong)channel_index)))];
				num3 = resamplerState_0.samp_frac_num[(int)((IntPtr)unchecked((long)resamplerState_0.samp_frac_numOffset + (long)((ulong)channel_index)))];
				float_ = resamplerState_0.float_0;
			}
			int num4 = resamplerState_0.memOffset + (int)(channel_index * resamplerState_0.mem_alloc_size);
			while (num2 < (int)in_len && num < (int)out_len)
			{
				double num5 = 0.0;
				int i = 0;
				while (num2 - filt_len + 1 + i < 0)
				{
					num5 += GloabFunc.MULT16_16((double)float_[num4 + num2 + i], (double)resamplerState_0.sinc_table[(int)checked((IntPtr)unchecked((long)resamplerState_0.sinc_tableOffset + (long)((ulong)(num3 * resamplerState_0.filt_len)) + (long)i))]);
					i++;
				}
				if (_in != null)
				{
					int num6 = _inOffset + resamplerState_0.in_stride * (num2 - filt_len + 1 + i);
					while (i < filt_len)
					{
						num5 += GloabFunc.MULT16_16((double)_in[num6], (double)resamplerState_0.sinc_table[(int)checked((IntPtr)unchecked((long)resamplerState_0.sinc_tableOffset + (long)((ulong)(num3 * resamplerState_0.filt_len)) + (long)i))]);
						num6 += resamplerState_0.in_stride;
						i++;
					}
				}
				_out[_outOffset] = (float)num5;
				_outOffset += resamplerState_0.out_stride;
				num++;
				num2 += resamplerState_0.int_advance;
				num3 += (uint)resamplerState_0.frac_advance;
				if (num3 >= resamplerState_0.den_rate)
				{
					num3 -= resamplerState_0.den_rate;
					num2++;
				}
			}
			checked
			{
				resamplerState_0.last_sample[(int)((IntPtr)unchecked((long)resamplerState_0.last_sampleOffset + (long)((ulong)channel_index)))] = num2;
				resamplerState_0.samp_frac_num[(int)((IntPtr)unchecked((long)resamplerState_0.samp_frac_numOffset + (long)((ulong)channel_index)))] = num3;
				return num;
			}
		}
		private static int resampler_basic_interpolate_single(GloabFunc.ResamplerState resamplerState_0, uint channel_index, float[] _in, int _inOffset, ref uint in_len, float[] _out, int _outOffset, ref uint out_len)
		{
			int filt_len = (int)resamplerState_0.filt_len;
			int num = 0;
			int num2;
			uint num3;
			float[] float_;
			checked
			{
				num2 = resamplerState_0.last_sample[(int)((IntPtr)unchecked((long)resamplerState_0.last_sampleOffset + (long)((ulong)channel_index)))];
				num3 = resamplerState_0.samp_frac_num[(int)((IntPtr)unchecked((long)resamplerState_0.samp_frac_numOffset + (long)((ulong)channel_index)))];
				float_ = resamplerState_0.float_0;
			}
			int num4 = resamplerState_0.memOffset + (int)(channel_index * resamplerState_0.mem_alloc_size);
			while (num2 < (int)in_len && num < (int)out_len)
			{
				float[] array = new float[4];
				float[] array2 = array;
				float[] array3 = new float[4];
				int num5 = (int)(num3 * resamplerState_0.oversample / resamplerState_0.den_rate);
				float frac = num3 * resamplerState_0.oversample % resamplerState_0.den_rate / resamplerState_0.den_rate;
				int i = 0;
				while (num2 - filt_len + 1 + i < 0)
				{
					float float_2 = float_[num4 + num2 + i];
					array2[0] += GloabFunc.MULT16_16(float_2, resamplerState_0.sinc_table[(int)checked((IntPtr)unchecked((long)(resamplerState_0.sinc_tableOffset + 4) + (long)(i + 1) * (long)((ulong)resamplerState_0.oversample) - (long)num5 - 2L))]);
					array2[1] += GloabFunc.MULT16_16(float_2, resamplerState_0.sinc_table[(int)checked((IntPtr)unchecked((long)(resamplerState_0.sinc_tableOffset + 4) + (long)(i + 1) * (long)((ulong)resamplerState_0.oversample) - (long)num5 - 1L))]);
					array2[2] += GloabFunc.MULT16_16(float_2, resamplerState_0.sinc_table[(int)checked((IntPtr)unchecked((long)(resamplerState_0.sinc_tableOffset + 4) + (long)(i + 1) * (long)((ulong)resamplerState_0.oversample) - (long)num5))]);
					array2[3] += GloabFunc.MULT16_16(float_2, resamplerState_0.sinc_table[(int)checked((IntPtr)unchecked((long)(resamplerState_0.sinc_tableOffset + 4) + (long)(i + 1) * (long)((ulong)resamplerState_0.oversample) - (long)num5 + 1L))]);
					i++;
				}
				if (_in != null)
				{
					int num6 = _inOffset + resamplerState_0.in_stride * (num2 - filt_len + 1 + i);
					while (i < filt_len)
					{
						float float_3 = _in[num6];
						num6 += resamplerState_0.in_stride;
						array2[0] += GloabFunc.MULT16_16(float_3, resamplerState_0.sinc_table[(int)checked((IntPtr)unchecked((long)(resamplerState_0.sinc_tableOffset + 4) + (long)(i + 1) * (long)((ulong)resamplerState_0.oversample) - (long)num5 - 2L))]);
						array2[1] += GloabFunc.MULT16_16(float_3, resamplerState_0.sinc_table[(int)checked((IntPtr)unchecked((long)(resamplerState_0.sinc_tableOffset + 4) + (long)(i + 1) * (long)((ulong)resamplerState_0.oversample) - (long)num5 - 1L))]);
						array2[2] += GloabFunc.MULT16_16(float_3, resamplerState_0.sinc_table[(int)checked((IntPtr)unchecked((long)(resamplerState_0.sinc_tableOffset + 4) + (long)(i + 1) * (long)((ulong)resamplerState_0.oversample) - (long)num5))]);
						array2[3] += GloabFunc.MULT16_16(float_3, resamplerState_0.sinc_table[(int)checked((IntPtr)unchecked((long)(resamplerState_0.sinc_tableOffset + 4) + (long)(i + 1) * (long)((ulong)resamplerState_0.oversample) - (long)num5 + 1L))]);
						i++;
					}
				}
				GloabFunc.cubic_coef(frac, array3, 0);
				float float_4 = GloabFunc.MULT16_32_Q15(array3[0], array2[0]) + GloabFunc.MULT16_32_Q15(array3[1], array2[1]) + GloabFunc.MULT16_32_Q15(array3[2], array2[2]) + GloabFunc.MULT16_32_Q15(array3[3], array2[3]);
				_out[_outOffset] = GloabFunc.PSHR32(float_4, 15);
				_outOffset += resamplerState_0.out_stride;
				num++;
				num2 += resamplerState_0.int_advance;
				num3 += (uint)resamplerState_0.frac_advance;
				if (num3 >= resamplerState_0.den_rate)
				{
					num3 -= resamplerState_0.den_rate;
					num2++;
				}
			}
			checked
			{
				resamplerState_0.last_sample[(int)((IntPtr)unchecked((long)resamplerState_0.last_sampleOffset + (long)((ulong)channel_index)))] = num2;
				resamplerState_0.samp_frac_num[(int)((IntPtr)unchecked((long)resamplerState_0.samp_frac_numOffset + (long)((ulong)channel_index)))] = num3;
				return num;
			}
		}
		private static int resampler_basic_interpolate_double(GloabFunc.ResamplerState resamplerState_0, uint channel_index, float[] _in, int _inOffset, ref uint in_len, float[] _out, int _outOffset, ref uint out_len)
		{
			int filt_len = (int)resamplerState_0.filt_len;
			int num = 0;
			int num2;
			int num3;
			float[] float_;
			checked
			{
				num2 = resamplerState_0.last_sample[(int)((IntPtr)unchecked((long)resamplerState_0.last_sampleOffset + (long)((ulong)channel_index)))];
				num3 = (int)resamplerState_0.samp_frac_num[(int)((IntPtr)unchecked((long)resamplerState_0.samp_frac_numOffset + (long)((ulong)channel_index)))];
				float_ = resamplerState_0.float_0;
			}
			int num4 = (int)((long)resamplerState_0.memOffset + (long)((ulong)(channel_index * resamplerState_0.mem_alloc_size)));
			while (num2 < (int)in_len && num < (int)out_len)
			{
				double[] array = new double[4];
				double[] array2 = array;
				float[] array3 = new float[4];
				float num5 = (float)num3 / resamplerState_0.den_rate;
				int num6 = (int)((long)num3 * (long)((ulong)resamplerState_0.oversample) / (long)((ulong)resamplerState_0.den_rate));
				float frac = num5 * resamplerState_0.oversample - (float)num6;
				int i = 0;
				while (num2 - filt_len + 1 + i < 0)
				{
					double double_ = (double)float_[num4 + num2 + i];
					array2[0] += GloabFunc.MULT16_16(double_, (double)resamplerState_0.sinc_table[(int)checked((IntPtr)unchecked((long)(resamplerState_0.sinc_tableOffset + 4) + (long)(i + 1) * (long)((ulong)resamplerState_0.oversample) - (long)num6 - 2L))]);
					array2[1] += GloabFunc.MULT16_16(double_, (double)resamplerState_0.sinc_table[(int)checked((IntPtr)unchecked((long)(resamplerState_0.sinc_tableOffset + 4) + (long)(i + 1) * (long)((ulong)resamplerState_0.oversample) - (long)num6 - 1L))]);
					array2[2] += GloabFunc.MULT16_16(double_, (double)resamplerState_0.sinc_table[(int)checked((IntPtr)unchecked((long)(resamplerState_0.sinc_tableOffset + 4) + (long)(i + 1) * (long)((ulong)resamplerState_0.oversample) - (long)num6))]);
					array2[3] += GloabFunc.MULT16_16(double_, (double)resamplerState_0.sinc_table[(int)checked((IntPtr)unchecked((long)(resamplerState_0.sinc_tableOffset + 4) + (long)(i + 1) * (long)((ulong)resamplerState_0.oversample) - (long)num6 + 1L))]);
					i++;
				}
				if (_in != null)
				{
					int num7 = _inOffset + resamplerState_0.in_stride * (num2 - filt_len + 1 + i);
					while (i < filt_len)
					{
						double double_2 = (double)_in[num7];
						num7 += resamplerState_0.in_stride;
						array2[0] += GloabFunc.MULT16_16(double_2, (double)resamplerState_0.sinc_table[(int)checked((IntPtr)unchecked((long)(resamplerState_0.sinc_tableOffset + 4) + (long)(i + 1) * (long)((ulong)resamplerState_0.oversample) - (long)num6 - 2L))]);
						array2[1] += GloabFunc.MULT16_16(double_2, (double)resamplerState_0.sinc_table[(int)checked((IntPtr)unchecked((long)(resamplerState_0.sinc_tableOffset + 4) + (long)(i + 1) * (long)((ulong)resamplerState_0.oversample) - (long)num6 - 1L))]);
						array2[2] += GloabFunc.MULT16_16(double_2, (double)resamplerState_0.sinc_table[(int)checked((IntPtr)unchecked((long)(resamplerState_0.sinc_tableOffset + 4) + (long)(i + 1) * (long)((ulong)resamplerState_0.oversample) - (long)num6))]);
						array2[3] += GloabFunc.MULT16_16(double_2, (double)resamplerState_0.sinc_table[(int)checked((IntPtr)unchecked((long)(resamplerState_0.sinc_tableOffset + 4) + (long)(i + 1) * (long)((ulong)resamplerState_0.oversample) - (long)num6 + 1L))]);
						i++;
					}
				}
				GloabFunc.cubic_coef(frac, array3, 0);
				float float_2 = (float)((int)((double)array3[0] * array2[0] + (double)array3[1] * array2[1] + (double)array3[2] * array2[2] + (double)array3[3] * array2[3]));
				_out[_outOffset] = GloabFunc.PSHR32(float_2, 15);
				_outOffset += resamplerState_0.out_stride;
				num++;
				num2 += resamplerState_0.int_advance;
				num3 += resamplerState_0.frac_advance;
				if ((long)num3 >= (long)((ulong)resamplerState_0.den_rate))
				{
					num3 -= (int)resamplerState_0.den_rate;
					num2++;
				}
			}
			checked
			{
				resamplerState_0.last_sample[(int)((IntPtr)unchecked((long)resamplerState_0.last_sampleOffset + (long)((ulong)channel_index)))] = num2;
				resamplerState_0.samp_frac_num[(int)((IntPtr)unchecked((long)resamplerState_0.samp_frac_numOffset + (long)((ulong)channel_index)))] = (uint)num3;
				return num;
			}
		}
		private static void update_filter(GloabFunc.ResamplerState resamplerState_0)
		{
			uint filt_len = resamplerState_0.filt_len;
			resamplerState_0.oversample = (uint)DefineConstants.quality_map[resamplerState_0.quality].oversample;
			resamplerState_0.filt_len = (uint)DefineConstants.quality_map[resamplerState_0.quality].base_length;
			if (resamplerState_0.num_rate > resamplerState_0.den_rate)
			{
				resamplerState_0.cutoff = DefineConstants.quality_map[resamplerState_0.quality].downsample_bandwidth * resamplerState_0.den_rate / resamplerState_0.num_rate;
				resamplerState_0.filt_len = resamplerState_0.filt_len * resamplerState_0.num_rate / resamplerState_0.den_rate;
				resamplerState_0.filt_len &= 4294967292u;
				if (2u * resamplerState_0.den_rate < resamplerState_0.num_rate)
				{
					resamplerState_0.oversample >>= 1;
				}
				if (4u * resamplerState_0.den_rate < resamplerState_0.num_rate)
				{
					resamplerState_0.oversample >>= 1;
				}
				if (8u * resamplerState_0.den_rate < resamplerState_0.num_rate)
				{
					resamplerState_0.oversample >>= 1;
				}
				if (16u * resamplerState_0.den_rate < resamplerState_0.num_rate)
				{
					resamplerState_0.oversample >>= 1;
				}
				if (resamplerState_0.oversample < 1u)
				{
					resamplerState_0.oversample = 1u;
				}
			}
			else
			{
				resamplerState_0.cutoff = DefineConstants.quality_map[resamplerState_0.quality].upsample_bandwidth;
			}
			if (resamplerState_0.den_rate <= resamplerState_0.oversample)
			{
				if (resamplerState_0.sinc_table == null)
				{
					resamplerState_0.sinc_table = new float[resamplerState_0.filt_len * resamplerState_0.den_rate];
					resamplerState_0.sinc_tableOffset = 0;
				}
				else
				{
					if (resamplerState_0.sinc_table_length < resamplerState_0.filt_len * resamplerState_0.den_rate)
					{
						resamplerState_0.sinc_table = GloabFunc.xve_realloc(resamplerState_0.sinc_table, resamplerState_0.sinc_tableOffset, (int)(resamplerState_0.filt_len * resamplerState_0.den_rate));
						resamplerState_0.sinc_tableOffset = 0;
						resamplerState_0.sinc_table_length = resamplerState_0.filt_len * resamplerState_0.den_rate;
					}
				}
				for (uint num = 0u; num < resamplerState_0.den_rate; num += 1u)
				{
					int num2 = 0;
					while ((long)num2 < (long)((ulong)resamplerState_0.filt_len))
					{
						resamplerState_0.sinc_table[(int)checked((IntPtr)unchecked((long)resamplerState_0.sinc_tableOffset + (long)((ulong)(num * resamplerState_0.filt_len)) + (long)num2))] = GloabFunc.sinc(resamplerState_0.cutoff, (float)(num2 - (int)(resamplerState_0.filt_len / 2u) + 1) - num / resamplerState_0.den_rate, (int)resamplerState_0.filt_len, DefineConstants.quality_map[resamplerState_0.quality].window_func);
						num2++;
					}
				}
				if (resamplerState_0.quality > 8)
				{
					resamplerState_0.resampler_ptr = new GloabFunc.resampler_basic_func(GloabFunc.resampler_basic_direct_double);
				}
				else
				{
					resamplerState_0.resampler_ptr = new GloabFunc.resampler_basic_func(GloabFunc.resampler_basic_direct_single);
				}
			}
			else
			{
				if (resamplerState_0.sinc_table == null)
				{
					resamplerState_0.sinc_table = new float[resamplerState_0.filt_len * resamplerState_0.oversample + 8u];
					resamplerState_0.sinc_tableOffset = 0;
				}
				else
				{
					if (resamplerState_0.sinc_table_length < resamplerState_0.filt_len * resamplerState_0.oversample + 8u)
					{
						resamplerState_0.sinc_table = GloabFunc.xve_realloc(resamplerState_0.sinc_table, resamplerState_0.sinc_tableOffset, (int)(resamplerState_0.filt_len * resamplerState_0.oversample + 8u));
						resamplerState_0.sinc_tableOffset = 0;
						resamplerState_0.sinc_table_length = resamplerState_0.filt_len * resamplerState_0.oversample + 8u;
					}
				}
				for (int i = -4; i < (int)(resamplerState_0.oversample * resamplerState_0.filt_len + 4u); i++)
				{
					resamplerState_0.sinc_table[resamplerState_0.sinc_tableOffset + i + 4] = GloabFunc.sinc(resamplerState_0.cutoff, (float)i / resamplerState_0.oversample - resamplerState_0.filt_len / 2u, (int)resamplerState_0.filt_len, DefineConstants.quality_map[resamplerState_0.quality].window_func);
				}
				if (resamplerState_0.quality > 8)
				{
					resamplerState_0.resampler_ptr = new GloabFunc.resampler_basic_func(GloabFunc.resampler_basic_interpolate_double);
				}
				else
				{
					resamplerState_0.resampler_ptr = new GloabFunc.resampler_basic_func(GloabFunc.resampler_basic_interpolate_single);
				}
			}
			resamplerState_0.int_advance = (int)(resamplerState_0.num_rate / resamplerState_0.den_rate);
			resamplerState_0.frac_advance = (int)(resamplerState_0.num_rate % resamplerState_0.den_rate);
			if (resamplerState_0.float_0 == null)
			{
				resamplerState_0.float_0 = new float[resamplerState_0.nb_channels * (resamplerState_0.filt_len - 1u)];
				resamplerState_0.memOffset = 0;
				for (uint num3 = 0u; num3 < resamplerState_0.nb_channels * (resamplerState_0.filt_len - 1u); num3 += 1u)
				{
					resamplerState_0.float_0[(int)checked((IntPtr)unchecked((long)resamplerState_0.memOffset + (long)((ulong)num3)))] = 0f;
				}
				resamplerState_0.mem_alloc_size = resamplerState_0.filt_len - 1u;
				return;
			}
			if (resamplerState_0.started == 0)
			{
				resamplerState_0.float_0 = GloabFunc.xve_realloc(resamplerState_0.float_0, resamplerState_0.memOffset, (int)(resamplerState_0.nb_channels * (resamplerState_0.filt_len - 1u)));
				resamplerState_0.memOffset = 0;
				for (uint num4 = 0u; num4 < resamplerState_0.nb_channels * (resamplerState_0.filt_len - 1u); num4 += 1u)
				{
					resamplerState_0.float_0[(int)checked((IntPtr)unchecked((long)resamplerState_0.memOffset + (long)((ulong)num4)))] = 0f;
				}
				resamplerState_0.mem_alloc_size = resamplerState_0.filt_len - 1u;
				return;
			}
			if (resamplerState_0.filt_len > filt_len)
			{
				int mem_alloc_size = (int)resamplerState_0.mem_alloc_size;
				if (resamplerState_0.filt_len - 1u > resamplerState_0.mem_alloc_size)
				{
					resamplerState_0.float_0 = GloabFunc.xve_realloc(resamplerState_0.float_0, resamplerState_0.memOffset, (int)(resamplerState_0.nb_channels * (resamplerState_0.filt_len - 1u)));
					resamplerState_0.memOffset = 0;
					resamplerState_0.mem_alloc_size = resamplerState_0.filt_len - 1u;
				}
				for (int j = (int)(resamplerState_0.nb_channels - 1u); j >= 0; j--)
				{
					uint num5 = filt_len + 2u * resamplerState_0.magic_samples[resamplerState_0.magic_samplesOffset + j];
					int k;
					for (k = (int)(filt_len - 2u + resamplerState_0.magic_samples[resamplerState_0.magic_samplesOffset + j]); k >= 0; k--)
					{
						resamplerState_0.float_0[(int)checked((IntPtr)unchecked((long)resamplerState_0.memOffset + (long)j * (long)((ulong)resamplerState_0.mem_alloc_size) + (long)k + (long)((ulong)resamplerState_0.magic_samples[resamplerState_0.magic_samplesOffset + j])))] = resamplerState_0.float_0[resamplerState_0.memOffset + j * mem_alloc_size + k];
					}
					k = 0;
					while ((long)k < (long)((ulong)resamplerState_0.magic_samples[resamplerState_0.magic_samplesOffset + j]))
					{
						resamplerState_0.float_0[(int)checked((IntPtr)unchecked((long)resamplerState_0.memOffset + (long)j * (long)((ulong)resamplerState_0.mem_alloc_size) + (long)k))] = 0f;
						k++;
					}
					resamplerState_0.magic_samples[resamplerState_0.magic_samplesOffset + j] = 0u;
					if (resamplerState_0.filt_len > num5)
					{
						k = 0;
						while ((long)k < (long)((ulong)(num5 - 1u)))
						{
							checked
							{
								resamplerState_0.float_0[(int)((IntPtr)unchecked((long)resamplerState_0.memOffset + (long)j * (long)((ulong)resamplerState_0.mem_alloc_size) + (long)((ulong)(resamplerState_0.filt_len - 2u) - (ulong)((long)k))))] = resamplerState_0.float_0[(int)((IntPtr)unchecked((long)resamplerState_0.memOffset + (long)j * (long)((ulong)resamplerState_0.mem_alloc_size) + (long)((ulong)(num5 - 2u) - (ulong)((long)k))))];
							}
							k++;
						}
						while ((long)k < (long)((ulong)(resamplerState_0.filt_len - 1u)))
						{
							resamplerState_0.float_0[(int)checked((IntPtr)unchecked((long)resamplerState_0.memOffset + (long)j * (long)((ulong)resamplerState_0.mem_alloc_size) + (long)((ulong)(resamplerState_0.filt_len - 2u) - (ulong)((long)k))))] = 0f;
							k++;
						}
						resamplerState_0.last_sample[resamplerState_0.last_sampleOffset + j] += (int)((resamplerState_0.filt_len - num5) / 2u);
					}
					else
					{
						resamplerState_0.magic_samples[resamplerState_0.magic_samplesOffset + j] = (num5 - resamplerState_0.filt_len) / 2u;
						k = 0;
						while ((long)k < (long)((ulong)(resamplerState_0.filt_len - 1u + resamplerState_0.magic_samples[resamplerState_0.magic_samplesOffset + j])))
						{
							checked
							{
								resamplerState_0.float_0[(int)((IntPtr)unchecked((long)resamplerState_0.memOffset + (long)j * (long)((ulong)resamplerState_0.mem_alloc_size) + (long)k))] = resamplerState_0.float_0[(int)((IntPtr)unchecked((long)resamplerState_0.memOffset + (long)j * (long)((ulong)resamplerState_0.mem_alloc_size) + (long)k + (long)((ulong)resamplerState_0.magic_samples[resamplerState_0.magic_samplesOffset + j])))];
							}
							k++;
						}
					}
				}
				return;
			}
			if (resamplerState_0.filt_len < filt_len)
			{
				for (uint num6 = 0u; num6 < resamplerState_0.nb_channels; num6 += 1u)
				{
					uint num7 = resamplerState_0.magic_samples[(int)checked((IntPtr)unchecked((long)resamplerState_0.magic_samplesOffset + (long)((ulong)num6)))];
					resamplerState_0.magic_samples[(int)checked((IntPtr)unchecked((long)resamplerState_0.magic_samplesOffset + (long)((ulong)num6)))] = (filt_len - resamplerState_0.filt_len) / 2u;
					for (uint num8 = 0u; num8 < resamplerState_0.filt_len - 1u + resamplerState_0.magic_samples[(int)checked((IntPtr)unchecked((long)resamplerState_0.magic_samplesOffset + (long)((ulong)num6)))] + num7; num8 += 1u)
					{
						checked
						{
							resamplerState_0.float_0[(int)((IntPtr)unchecked((long)resamplerState_0.memOffset + (long)((ulong)(num6 * resamplerState_0.mem_alloc_size)) + (long)((ulong)num8)))] = resamplerState_0.float_0[(int)((IntPtr)unchecked((long)resamplerState_0.memOffset + (long)((ulong)(num6 * resamplerState_0.mem_alloc_size)) + (long)((ulong)num8) + (long)((ulong)resamplerState_0.magic_samples[(int)checked((IntPtr)unchecked((long)resamplerState_0.magic_samplesOffset + (long)((ulong)num6)))])))];
						}
					}
					resamplerState_0.magic_samples[(int)checked((IntPtr)unchecked((long)resamplerState_0.magic_samplesOffset + (long)((ulong)num6)))] += num7;
				}
			}
		}
		public static GloabFunc.ResamplerState resampler_init(uint nb_channels, uint in_rate, uint out_rate, int quality, ref int int_0)
		{
			return GloabFunc.resampler_init_frac(nb_channels, in_rate, out_rate, in_rate, out_rate, quality, ref int_0);
		}
		private static GloabFunc.ResamplerState resampler_init_frac(uint nb_channels, uint ratio_num, uint ratio_den, uint in_rate, uint out_rate, int quality, ref int int_0)
		{
			if (quality <= 10 && quality >= 0)
			{
				GloabFunc.ResamplerState resamplerState = new GloabFunc.ResamplerState();
				resamplerState.initialised = 0;
				resamplerState.started = 0;
				resamplerState.in_rate = 0u;
				resamplerState.out_rate = 0u;
				resamplerState.num_rate = 0u;
				resamplerState.den_rate = 0u;
				resamplerState.quality = -1;
				resamplerState.sinc_table_length = 0u;
				resamplerState.mem_alloc_size = 0u;
				resamplerState.filt_len = 0u;
				resamplerState.float_0 = null;
				resamplerState.memOffset = 0;
				resamplerState.cutoff = 1f;
				resamplerState.nb_channels = nb_channels;
				resamplerState.in_stride = 1;
				resamplerState.out_stride = 1;
				resamplerState.last_sample = new int[nb_channels];
				resamplerState.last_sampleOffset = 0;
				resamplerState.magic_samples = new uint[nb_channels];
				resamplerState.magic_samplesOffset = 0;
				resamplerState.samp_frac_num = new uint[nb_channels];
				resamplerState.samp_frac_numOffset = 0;
				int num = 0;
				while ((long)num < (long)((ulong)nb_channels))
				{
					resamplerState.last_sample[resamplerState.last_sampleOffset + num] = 0;
					resamplerState.magic_samples[resamplerState.magic_samplesOffset + num] = 0u;
					resamplerState.samp_frac_num[resamplerState.samp_frac_numOffset + num] = 0u;
					num++;
				}
				GloabFunc.resampler_set_quality(resamplerState, quality);
				GloabFunc.resampler_set_rate_frac(resamplerState, ratio_num, ratio_den, in_rate, out_rate);
				GloabFunc.update_filter(resamplerState);
				resamplerState.initialised = 1;
				int_0 = 0;
				return resamplerState;
			}
			int_0 = 3;
			return null;
		}
		public static void resampler_destroy(GloabFunc.ResamplerState resamplerState_0)
		{
			resamplerState_0.float_0 = null;
			resamplerState_0.memOffset = 0;
			resamplerState_0.sinc_table = null;
			resamplerState_0.sinc_tableOffset = 0;
			resamplerState_0.last_sample = null;
			resamplerState_0.last_sampleOffset = 0;
			resamplerState_0.magic_samples = null;
			resamplerState_0.magic_samplesOffset = 0;
			resamplerState_0.samp_frac_num = null;
			resamplerState_0.samp_frac_numOffset = 0;
			resamplerState_0 = null;
		}
		private static int resampler_process_native(GloabFunc.ResamplerState resamplerState_0, uint channel_index, float[] inArray, int inArrayOffset, ref uint in_len, float[] outArray, int outArrayOffset, ref uint out_len)
		{
			int filt_len = (int)resamplerState_0.filt_len;
			uint num = 0u;
			float[] float_ = resamplerState_0.float_0;
			int num2 = resamplerState_0.memOffset + (int)(channel_index * resamplerState_0.mem_alloc_size);
			resamplerState_0.started = 1;
			int num6;
			checked
			{
				if (resamplerState_0.magic_samples[(int)((IntPtr)unchecked((long)resamplerState_0.magic_samplesOffset + (long)((ulong)channel_index)))] != 0u)
				{
					int in_stride = resamplerState_0.in_stride;
					uint num3 = resamplerState_0.magic_samples[(int)((IntPtr)unchecked((long)resamplerState_0.magic_samplesOffset + (long)((ulong)channel_index)))];
					num = out_len;
					uint num4 = resamplerState_0.magic_samples[(int)((IntPtr)unchecked((long)resamplerState_0.magic_samplesOffset + (long)((ulong)channel_index)))];
					resamplerState_0.magic_samples[(int)((IntPtr)unchecked((long)resamplerState_0.magic_samplesOffset + (long)((ulong)channel_index)))] = 0u;
					resamplerState_0.in_stride = 1;
					unchecked
					{
						GloabFunc.resampler_process_native(resamplerState_0, channel_index, float_, num2 + filt_len - 1, ref num3, outArray, outArrayOffset, ref num);
						resamplerState_0.in_stride = in_stride;
						if (num3 < num4)
						{
							resamplerState_0.magic_samples[(int)checked((IntPtr)unchecked((long)resamplerState_0.magic_samplesOffset + (long)((ulong)channel_index)))] = num4 - num3;
							for (uint num5 = 0u; num5 < resamplerState_0.magic_samples[(int)checked((IntPtr)unchecked((long)resamplerState_0.magic_samplesOffset + (long)((ulong)channel_index)))]; num5 += 1u)
							{
								checked
								{
									float_[(int)((IntPtr)unchecked((long)(num2 + filt_len - 1) + (long)((ulong)num5)))] = float_[(int)((IntPtr)unchecked((long)(num2 + filt_len - 1) + (long)((ulong)num5) + (long)((ulong)num3)))];
								}
							}
						}
						outArrayOffset += (int)(num * (uint)resamplerState_0.out_stride);
						out_len -= num;
					}
				}
				num6 = resamplerState_0.resampler_ptr(resamplerState_0, channel_index, inArray, inArrayOffset, ref in_len, outArray, outArrayOffset, ref out_len);
				if (resamplerState_0.last_sample[(int)((IntPtr)unchecked((long)resamplerState_0.last_sampleOffset + (long)((ulong)channel_index)))] < (int)in_len)
				{
					in_len = (uint)resamplerState_0.last_sample[(int)((IntPtr)unchecked((long)resamplerState_0.last_sampleOffset + (long)((ulong)channel_index)))];
				}
			}
			out_len = (uint)((long)num6 + (long)((ulong)num));
			resamplerState_0.last_sample[(int)checked((IntPtr)unchecked((long)resamplerState_0.last_sampleOffset + (long)((ulong)channel_index)))] -= (int)in_len;
			int i;
			for (i = 0; i < filt_len - 1 - (int)in_len; i++)
			{
				float_[num2 + i] = float_[(int)checked((IntPtr)unchecked((long)(num2 + i) + (long)((ulong)in_len)))];
			}
			if (inArray != null)
			{
				while (i < filt_len - 1)
				{
					float_[num2 + i] = inArray[(int)checked((IntPtr)unchecked((long)inArrayOffset + (long)resamplerState_0.in_stride * ((long)i + (long)((ulong)in_len) - (long)filt_len + 1L)))];
					i++;
				}
			}
			else
			{
				while (i < filt_len - 1)
				{
					float_[num2 + i] = 0f;
					i++;
				}
			}
			return 0;
		}
		private static int resampler_process_float(GloabFunc.ResamplerState resamplerState_0, uint channel_index, float[] inArray, int inArrayOffset, ref uint in_len, float[] outArray, int outArrayOffset, ref uint out_len)
		{
			return GloabFunc.resampler_process_native(resamplerState_0, channel_index, inArray, inArrayOffset, ref in_len, outArray, outArrayOffset, ref out_len);
		}
		public static int resampler_process_int(GloabFunc.ResamplerState resamplerState_0, uint channel_index, short[] inArray, int inArrayOffset, ref uint in_len, short[] outArray, int outArrayOffset, ref uint out_len)
		{
			float[] array = new float[1024];
			float[] array2 = new float[1024];
			uint num = in_len;
			uint num2 = out_len;
			int in_stride = resamplerState_0.in_stride;
			int out_stride = resamplerState_0.out_stride;
			while (num != 0u && num2 != 0u)
			{
				uint num3 = num;
				uint num4 = num2;
				if (num3 > 1024u)
				{
					num3 = 1024u;
				}
				if (num4 > 1024u)
				{
					num4 = 1024u;
				}
				if (inArray != null)
				{
					for (uint num5 = 0u; num5 < num3; num5 += 1u)
					{
						array[(int)((UIntPtr)num5)] = (float)inArray[(int)checked((IntPtr)unchecked((long)inArrayOffset + (long)((ulong)num5 * (ulong)((long)resamplerState_0.in_stride))))];
					}
					resamplerState_0.out_stride = 1;
					resamplerState_0.in_stride = 1;
					GloabFunc.resampler_process_native(resamplerState_0, channel_index, array, 0, ref num3, array2, 0, ref num4);
				}
				else
				{
					resamplerState_0.out_stride = 1;
					resamplerState_0.in_stride = 1;
					GloabFunc.resampler_process_native(resamplerState_0, channel_index, null, 0, ref num3, array2, 0, ref num4);
				}
				resamplerState_0.in_stride = in_stride;
				resamplerState_0.out_stride = out_stride;
				for (uint num5 = 0u; num5 < num4; num5 += 1u)
				{
					outArray[(int)checked((IntPtr)unchecked((long)outArrayOffset + (long)((ulong)num5 * (ulong)((long)resamplerState_0.out_stride))))] = GloabFunc.WORD2INT(array2[(int)((UIntPtr)num5)]);
				}
				outArrayOffset += (int)num4;
				inArrayOffset += (int)num3;
				num -= num3;
				num2 -= num4;
			}
			in_len -= num;
			out_len -= num2;
			return 0;
		}
		private static int resampler_process_interleaved_float(GloabFunc.ResamplerState resamplerState_0, float[] inArray, int inArrayOffset, ref uint in_len, float[] outArray, int outArrayOffset, ref uint out_len)
		{
			uint num = out_len;
			int in_stride = resamplerState_0.in_stride;
			int out_stride = resamplerState_0.out_stride;
			resamplerState_0.in_stride = (resamplerState_0.out_stride = (int)resamplerState_0.nb_channels);
			for (uint num2 = 0u; num2 < resamplerState_0.nb_channels; num2 += 1u)
			{
				out_len = num;
				if (inArray != null)
				{
					GloabFunc.resampler_process_float(resamplerState_0, num2, inArray, inArrayOffset + (int)num2, ref in_len, outArray, (int)((long)outArrayOffset + (long)((ulong)num2)), ref out_len);
				}
				else
				{
					GloabFunc.resampler_process_float(resamplerState_0, num2, null, 0, ref in_len, outArray, (int)((long)outArrayOffset + (long)((ulong)num2)), ref out_len);
				}
			}
			resamplerState_0.in_stride = in_stride;
			resamplerState_0.out_stride = out_stride;
			return 0;
		}
		private static int resampler_process_interleaved_int(GloabFunc.ResamplerState resamplerState_0, short[] inArray, int inArrayOffset, ref uint in_len, short[] outArray, int outArrayOffset, ref uint out_len)
		{
			uint num = out_len;
			int in_stride = resamplerState_0.in_stride;
			int out_stride = resamplerState_0.out_stride;
			resamplerState_0.in_stride = (resamplerState_0.out_stride = (int)resamplerState_0.nb_channels);
			for (uint num2 = 0u; num2 < resamplerState_0.nb_channels; num2 += 1u)
			{
				out_len = num;
				if (inArray != null)
				{
					GloabFunc.resampler_process_int(resamplerState_0, num2, inArray, (int)((long)inArrayOffset + (long)((ulong)num2)), ref in_len, outArray, (int)((long)outArrayOffset + (long)((ulong)num2)), ref out_len);
				}
				else
				{
					GloabFunc.resampler_process_int(resamplerState_0, num2, null, 0, ref in_len, outArray, (int)((long)outArrayOffset + (long)((ulong)num2)), ref out_len);
				}
			}
			resamplerState_0.in_stride = in_stride;
			resamplerState_0.out_stride = out_stride;
			return 0;
		}
		private static int resampler_set_rate(GloabFunc.ResamplerState resamplerState_0, uint in_rate, uint out_rate)
		{
			return GloabFunc.resampler_set_rate_frac(resamplerState_0, in_rate, out_rate, in_rate, out_rate);
		}
		private static void resampler_get_rate(GloabFunc.ResamplerState resamplerState_0, ref uint in_rate, ref uint out_rate)
		{
			in_rate = resamplerState_0.in_rate;
			out_rate = resamplerState_0.out_rate;
		}
		private static int resampler_set_rate_frac(GloabFunc.ResamplerState resamplerState_0, uint ratio_num, uint ratio_den, uint in_rate, uint out_rate)
		{
			if (resamplerState_0.in_rate == in_rate && resamplerState_0.out_rate == out_rate && resamplerState_0.num_rate == ratio_num && resamplerState_0.den_rate == ratio_den)
			{
				return 0;
			}
			uint den_rate = resamplerState_0.den_rate;
			resamplerState_0.in_rate = in_rate;
			resamplerState_0.out_rate = out_rate;
			resamplerState_0.num_rate = ratio_num;
			resamplerState_0.den_rate = ratio_den;
			for (uint num = 2u; num <= GloabFunc.IMIN(resamplerState_0.num_rate, resamplerState_0.den_rate); num += 1u)
			{
				while (resamplerState_0.num_rate % num == 0u && resamplerState_0.den_rate % num == 0u)
				{
					resamplerState_0.num_rate /= num;
					resamplerState_0.den_rate /= num;
				}
			}
			if (den_rate > 0u)
			{
				for (uint num2 = 0u; num2 < resamplerState_0.nb_channels; num2 += 1u)
				{
					resamplerState_0.samp_frac_num[(int)checked((IntPtr)unchecked((long)resamplerState_0.samp_frac_numOffset + (long)((ulong)num2)))] = resamplerState_0.samp_frac_num[(int)checked((IntPtr)unchecked((long)resamplerState_0.samp_frac_numOffset + (long)((ulong)num2)))] * resamplerState_0.den_rate / den_rate;
					if (resamplerState_0.samp_frac_num[(int)checked((IntPtr)unchecked((long)resamplerState_0.samp_frac_numOffset + (long)((ulong)num2)))] >= resamplerState_0.den_rate)
					{
						resamplerState_0.samp_frac_num[(int)checked((IntPtr)unchecked((long)resamplerState_0.samp_frac_numOffset + (long)((ulong)num2)))] = resamplerState_0.den_rate - 1u;
					}
				}
			}
			if (resamplerState_0.initialised != 0)
			{
				GloabFunc.update_filter(resamplerState_0);
			}
			return 0;
		}
		private static void resampler_get_ratio(GloabFunc.ResamplerState resamplerState_0, ref uint ratio_num, ref uint ratio_den)
		{
			ratio_num = resamplerState_0.num_rate;
			ratio_den = resamplerState_0.den_rate;
		}
		private static int resampler_set_quality(GloabFunc.ResamplerState resamplerState_0, int quality)
		{
			if (quality > 10 || quality < 0)
			{
				return 3;
			}
			if (resamplerState_0.quality == quality)
			{
				return 0;
			}
			resamplerState_0.quality = quality;
			if (resamplerState_0.initialised != 0)
			{
				GloabFunc.update_filter(resamplerState_0);
			}
			return 0;
		}
		private static void resampler_get_quality(GloabFunc.ResamplerState resamplerState_0, ref int quality)
		{
			quality = resamplerState_0.quality;
		}
		private static void resampler_set_input_stride(GloabFunc.ResamplerState resamplerState_0, uint stride)
		{
			resamplerState_0.in_stride = (int)stride;
		}
		private static void resampler_get_input_stride(GloabFunc.ResamplerState resamplerState_0, ref uint stride)
		{
			stride = (uint)resamplerState_0.in_stride;
		}
		private static void resampler_set_output_stride(GloabFunc.ResamplerState resamplerState_0, uint stride)
		{
			resamplerState_0.out_stride = (int)stride;
		}
		private static void resampler_get_output_stride(GloabFunc.ResamplerState resamplerState_0, ref uint stride)
		{
			stride = (uint)resamplerState_0.out_stride;
		}
		private static int resampler_get_input_latency(GloabFunc.ResamplerState resamplerState_0)
		{
			return (int)(resamplerState_0.filt_len / 2u);
		}
		private static int resampler_get_output_latency(GloabFunc.ResamplerState resamplerState_0)
		{
			return (int)((resamplerState_0.filt_len / 2u * resamplerState_0.den_rate + (resamplerState_0.num_rate >> 1)) / resamplerState_0.num_rate);
		}
		private static int resampler_skip_zeros(GloabFunc.ResamplerState resamplerState_0)
		{
			int num = 0;
			while ((long)num < (long)((ulong)resamplerState_0.nb_channels))
			{
				resamplerState_0.last_sample[resamplerState_0.last_sampleOffset + num] = (int)(resamplerState_0.filt_len / 2u);
				num++;
			}
			return 0;
		}
		private static int resampler_reset_mem(GloabFunc.ResamplerState resamplerState_0)
		{
			int num = 0;
			while ((long)num < (long)((ulong)(resamplerState_0.nb_channels * (resamplerState_0.filt_len - 1u))))
			{
				resamplerState_0.float_0[resamplerState_0.memOffset + num] = 0f;
				num++;
			}
			return 0;
		}
		private static string resampler_strerror(int int_0)
		{
			switch (int_0)
			{
			case 0:
				return "Success.";
			case 1:
				return "Memory allocation failed.";
			case 2:
				return "Bad resampler state.";
			case 3:
				return "Invalid argument.";
			case 4:
				return "Input and output buffers overlap.";
			default:
				return "Unknown error. Bad error code or strange version mismatch.";
			}
		}
		public static void resamper_test()
		{
			int num = 0;
			int num2 = 320;
			short[] array = new short[320];
			short[] outArray = new short[320 << 3];
			for (int i = 0; i < num2; i++)
			{
				array[i] = (short)(100 - i);
			}
			uint num3 = (uint)num2;
			GloabFunc.ResamplerState resamplerState_ = GloabFunc.resampler_init(1u, 16000u, 8000u, 4, ref num);
			num3 = (uint)num2;
			uint num4 = num3 * 8000u / 16000u;
			GloabFunc.resampler_process_int(resamplerState_, 0u, array, 0, ref num3, outArray, 0, ref num4);
			GloabFunc.resampler_destroy(resamplerState_);
		}
	}
}
